// pagesProperty/pages/active/sign/index.js
var app = getApp(), fetchApi = require("../../../../utils/httpPost.js"), common_Js = require("../../../../component/common.js")
import Dialog from '../../../../component/vant/dialog/dialog';
import Toast from '../../../../component/vant/toast/toast';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    realName:'',
    phoneNum:'',
    activeId:'',
    remark:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if(options.id){
      this.data.activeId = parseInt(options.id)
    }
  },
  bindInput(e){
    let key = e.currentTarget.dataset.key;
    if(key == 'name'){      
      this.data.realName = e.detail;
    } else if(key == 'phone'){      
      this.data.phoneNum = e.detail;
    } else if(key == 'remark'){      
      this.data.remark = e.detail;
    }
  },
  goSubmit(){
    if(this.data.realName == ''){
      Toast.fail("请输入姓名");
      return ;
    }
    if(this.data.phoneNum == ''){
      Toast.fail("请输入手机号");
      return ;
    }
    if(this.data.remark == ''){
      Toast.fail("请输入备注信息");
      return ;
    }
    this.onHttpAddSign();
  },
  onHttpAddSign(){
    var that = this;
    fetchApi.httpPost('/active/add/sign', {
      active_id: that.data.activeId,
      phone_num:that.data.phoneNum,
      real_name: that.data.realName,
      remark: that.data.remark
    }, function (res) {
      console.log("报名参与", res)
      if(res.data.code == 0){
        Toast.success(res.data.msg)
        setTimeout(function(){
          wx.navigateBack({
            delta: -1,
          })
        },800)
      }else{
        Toast.fail(res.data.msg)
      }
    }, function () {
      
    })
  },


  
})